<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <ul>
        <li v-for="(item,index) in msg" :key="item.id" @click="del(item.id)">
          <span>{{item.num}}</span>
          <button @click="del(item.id)">{{item.del}}</button>
        </li>
      </ul>
      <button @click="reverseMsg">生成</button>
    </div>
    <script src="../vue.js"></script>
    <script>
      const app = new Vue({
        el: "#app",
        data: {
          msg: [],
        },
        methods: {
          reverseMsg() {
            this.msg.push({
              num: Math.floor(Math.random() * 20),
              del: "删除",
              id: Math.floor(Math.random() * 200000),
            });
          },
          del(id) {
            this.msg = this.msg.filter((item) => item.id !== id);
          },
        },
      });
    </script>
  </body>
</html>
